﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows.Forms;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;

namespace CodedUITestProject1
{
    public class otherGlobalFunctions
    {

        public static bool setPlaybackSettings ()
        {
            Playback.PlaybackSettings.DelayBetweenActions = 0;

            Playback.PlaybackSettings.MatchExactHierarchy = true;

            Playback.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.None;

            Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;

            return true;
        }

	public static string XML_getNodeValue (string strXMLPath,string strNodeName,int intIndex)
        {
            string strNodeValue = "False";

            int intNodeLength = 0;

            XmlDocument xml = new XmlDocument();

            xml.Load(strXMLPath);

            intNodeLength = xml.GetElementsByTagName(strNodeName).Count;

            if (intNodeLength > 0)
            {
                strNodeValue = xml.GetElementsByTagName(strNodeName).Item(intIndex).Value;
                
            }

            else
            {

                Assert.IsTrue(intNodeLength > 0, "XML Node - " + strNodeName + " - not found in the XML.");
                return "False";
            }


            return strNodeValue;
        }

        public static string Database_getColumnValue(string strConnString, string strUniqueResultQuery, string strColumn)
        {
            string strColValue = "False";

            SqlConnection sqlConn = new SqlConnection(strConnString);

            sqlConn.Open ();

            // create a SqlCommand object for this connection
            SqlCommand command = sqlConn.CreateCommand();
            command.CommandText = strUniqueResultQuery;
            command.CommandType = CommandType.Text;

            // execute the command that returns a SqlDataReader
            SqlDataReader reader = command.ExecuteReader();

            if (reader[strColumn].ToString().Length > 0) 
            {
                strColValue = reader[strColumn].ToString();

            }

            else
            {

                Assert.IsTrue(reader[strColumn].ToString().Length > 0, "SQL Query "+strUniqueResultQuery+" did not return any value.");
                return "False";
            }


            return strColValue;
        }
       
       

    }
}
